/*
package com.ruiyi.subway.web;

import com.ruiyi.subway.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

@Component("authTokenInterceptor")
public class AuthTokenInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    private UserService userService;
    @Autowired
    private UserAuthService userAuthService;
    @Autowired
    private RoleService roleService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        if (handler instanceof ResourceHttpRequestHandler) {
            return true;
        }
        if (handler instanceof ParameterizableViewController) {
            return true;
        }
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();

        AuthToken authAnnotation = method.getAnnotation(AuthToken.class);
        if (authAnnotation != null) {
            String authToken = request.getHeader(VcsHeaders.USER_AUTH_TOKEN);
            if (auth(authAnnotation, authToken)) {
                return true;
            }
            responseForMessage(response, "登录信息错误，请重新登录");
            return false;
        }
        return true;
    }

    private boolean auth(AuthToken authAnnotation, String authToken) {
        try {
            if (authAnnotation.authUser()) {
                //细粒度权限
                return authResource(authAnnotation.resource(), userService.authUser(authToken));
            } else {
                //仅认证token合法
                TokenEnum tokenEnum = userAuthService.authToken(authToken);
                return tokenEnum == TokenEnum.SUCCESS ;
            }
        } catch (Exception e) {
            return false;
        }
    }

    private boolean authResource(String resource, User user) throws IOException {
        if (isAdminUser(user) || StringUtils.isEmpty(resource)) {
            return true;
        }
        return roleService.authRole(user, resource);
    }

    private boolean isAdminUser(User user) {
        return RoleType.ADMIN.equals(user.getRoleName());
    }

    private void responseForMessage(HttpServletResponse response, String message) throws IOException {
        response.setContentType("application/json; charset=UTF-8");
        response.getWriter().write(new Gson().toJson(RestResponse.failed(message)));
    }

}
*/
